#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1010;

int num[N];
int n;
vector<int> level_order;
int idx;

// return 层数，最后一层个数
PII calc_root(int l, int r) {
    int len = r - l + 1;
    int level = 1;
    for (int i = 1; i <= 12; i ++ ) {
        int up = (1 << i) - 1;
        if (up < len) continue;
        if (up == len) return mk(i, 0);
        level = i;
        break;
    }
    return mk(level, len - ((1 << (level - 1)) - 1));
}

// 由于是层序遍历，思考想到bfs 
void bfs() {
    queue<PII> q;
    // 队列中存放一个区间[l, r]
    q.push(mk(0, n - 1));
    while (q.size()) {
        auto qt = q.front(); q.pop();
        int l = qt.first, r = qt.second;
        PII p = calc_root(l, r);
        int pos;
        // 如果是满完全二叉搜索树
        if (p.second == 0) 
            pos = l + (r - l) / 2;
        else {
            // 如果完全二叉搜索树最后一层过半
            if (p.second > (1 << (p.first - 1)) / 2) {
                pos = l + ((1 << (p.first - 1)) - 1);
            } else {
                // 如果完全二叉搜索树最后一层未过半
                pos = l + ((r - l + 1) - p.second - 1) / 2 + p.second;
            }
        }
        level_order.push_back(num[pos]);
        if (l <= pos - 1)
            q.push(mk(l, pos - 1));
        if (pos + 1 <= r)
            q.push(mk(pos + 1, r));
    }
}

// 如果使用dfs得出来的序列为前序遍历
void dfs(int l, int r) {
    if (l > r) return;
    PII p = calc_root(l, r);
    int pos;
    if (p.second == 0) 
        pos = l + (r - l) / 2;
    else {
        if (p.second > (1 << (p.first - 1)) / 2) {
            pos = l + ((1 << (p.first - 1)) - 1);
        } else {
            pos = l + ((r - l + 1) - p.second - 1) / 2 + p.second;
        }
    }
    preorder.push_back(num[pos]);
    dfs(l, pos - 1);
    dfs(pos + 1, r);
}


inline void solution() {
    cin >> n;
    for (int i = 0; i < n; i ++ ) 
        cin >> num[i];
    sort(num, num + n);
    bfs();
    cout << level_order[0];
    for (int i = 1; i < level_order.size(); i ++ ) 
        cout << " " << level_order[i];
    cout << endl;
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}